package com.yanqu.road.logic.activity.foxcard.game.effect;

import com.yanqu.road.entity.activity.foxcard.FoxBaseCard;
import com.yanqu.road.entity.activity.foxcard.FoxHandCard;
import com.yanqu.road.logic.activity.foxcard.FoxCardConfig;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardGameLogic;
import com.yanqu.road.logic.activity.foxcard.game.FoxCardShowInfo;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardShowType;
import com.yanqu.road.logic.activity.foxcard.game.eFoxCardTriggerType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 每次弃掉指定牌 / 花色，可以获得效果
 * 指定点数|花色| 0|0|0|0
 * 加筹码增幅值|乘筹码增幅值|加倍率增幅值|乘倍率增幅值|金币增幅值
 */
public class FoxCardEffect18 extends FoxCardEffectBase {
    @Override
    protected void effectHandle(FoxCardGameLogic gameLogic, FoxHandCard handCard) {
        FoxCardConfig config = gameLogic.getConfig();
        if (triggerType == eFoxCardTriggerType.ADD && handCard == null) {
            //生成指定的点数和花色
            int point = Integer.valueOf(effectConfig.getParamsList().get(0));
            int color = Integer.valueOf(effectConfig.getParamsList().get(1));
            if (point == -1) {
                point = config.getRandomHelper().next(1, config.getPointToScoreMap().size() + 1);
            }
            if (color == -1) {
                color = config.getRandomHelper().next(1, FoxCardGameLogic.CARD_COLOR_NUM + 1);
            }
            List<Long> effectValues = new ArrayList<>();
            effectValues.add((long) point);
            effectValues.add((long) color);
            effectValues.add(0L);
            effectCard.setEffectValues(effectValues);
        } else if (triggerType == eFoxCardTriggerType.DROP) {
            int point = effectCard.getEffectValues().get(0).intValue();
            int color = effectCard.getEffectValues().get(1).intValue();
            int level = effectCard.getEffectValues().get(2).intValue();

            //0表示没指定点数和花色
            int levelUp = 0;
            for (FoxHandCard dropHandCard : gameLogic.getDropHandCards()) {
                if (config.isNotPointAndNotColorHandCard(dropHandCard.getReinforceEffect())) {//石头牌没有花色和点数
                    continue;
                }
                if (point != 0 && gameLogic.getHandCardNowPoint(dropHandCard) != point) {
                    continue;
                }
                if (color != 0 && (dropHandCard.getColor() != color && !config.isAllColorHandCard(dropHandCard.getReinforceEffect()))) {
                    continue;
                }
                levelUp++;

                FoxCardShowInfo showInfo = gameLogic.newFoxShow(eFoxCardShowType.EFFECT_CARD_LV_UP.getValue());
                showInfo.setSettleCards(Collections.singletonList(effectCard));
                showInfo.setShowValue(1);
            }
            if (levelUp > 0) {
                level += levelUp;
                effectCard.getEffectValues().set(2, (long) level);
            }
        } else if (triggerType == eFoxCardTriggerType.AFTER_SCORE) {
            int level = effectCard.getEffectValues().get(2).intValue();
            int addBaseScore = Integer.valueOf(effectConfig.getUpgradeParamsList().get(0)) * level;
            int addBaseScoreMulti = Integer.valueOf(effectConfig.getUpgradeParamsList().get(1)) * level;
            int addBaseMulti = Integer.valueOf(effectConfig.getUpgradeParamsList().get(2)) * level;
            int addBaseMultiMulti = Integer.valueOf(effectConfig.getUpgradeParamsList().get(3)) * level;
            int goldChange = Integer.valueOf(effectConfig.getUpgradeParamsList().get(4)) * level;

            List<FoxBaseCard> foxEffectCards = Collections.singletonList(effectCard);
            gameLogic.addBaseScore(addBaseScore, foxEffectCards, null); //加基础筹码
            gameLogic.addBaseScoreMulti(addBaseScoreMulti, foxEffectCards, null); //当前基础筹码乘算
            gameLogic.addBaseMulti(addBaseMulti, foxEffectCards, null); //加基础倍率
            gameLogic.addBaseMultiMulti(addBaseMultiMulti, foxEffectCards, null); //当前基础倍率乘算
            gameLogic.goldChange(goldChange, foxEffectCards, null, triggerType); //加金币
        } else if (triggerType == eFoxCardTriggerType.ROUND_START) {//
            //改变指定的点数和花色
            int point = Integer.valueOf(effectConfig.getParamsList().get(0));
            int color = Integer.valueOf(effectConfig.getParamsList().get(1));
            if (point == -1) {
                point = config.getRandomHelper().next(1, config.getPointToScoreMap().size() + 1);
            }
            if (color == -1) {
                color = config.getRandomHelper().next(1, FoxCardGameLogic.CARD_COLOR_NUM + 1);
            }

            effectCard.getEffectValues().set(0, (long) point);
            effectCard.getEffectValues().set(1, (long) color);
        }
    }
}
